package
{
	import com.nana.framework.base.App;
	
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.system.Security;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	
	public class entry extends Sprite
	{
		private var mainLayer:Sprite;
		private var loadingLayer:Sprite;
		private var loadingSprite:DisplayObject;
		private var $platformIniUrl:String = "files/";
		private var $platformOutUrl:String = "";
		private var $platformEntryUrl:String = "";
		
		public function entry()
		{
			this.setStage();
			App.appStage = this.stage;
			if ((stage.stageWidth > 0) && (stage.stageHeight > 0)){
				this.init();
			} else {
				stage.addEventListener(Event.RESIZE, this.onResize);
			}
		}
		
		private function onResize(event:Event):void{
			if ((stage.stageWidth > 0) && (stage.stageHeight > 0)){
				stage.removeEventListener(Event.RESIZE, this.onResize);
				this.init();
			}
		}
		
		private function init():void{
			var _local1:Array;
			var _local2:String;
			PlatformFlashValue.value = this.stage.loaderInfo.parameters;
			Platform.registerPlaform(PiratePlatform);
			Platform.getInstance().checkEntry();
			this.mainLayer = new Sprite();
			addChild(this.mainLayer);
			this.loadingLayer = new Sprite();
			addChild(this.loadingLayer);
			Security.allowDomain("*");
			Security.allowInsecureDomain("*");
			if (((!((PlatformFlashValue.value == null))) && (PlatformFlashValue.value.hasOwnProperty("lang")))){
				if (PlatformFlashValue.value["lang"] == "zh-cn"){
					Dll.getInstance().lang = "cn";
				} else if (PlatformFlashValue.value["lang"] == "zh-tw"){
					Dll.getInstance().lang = "tw";
				} else if (PlatformFlashValue.value["lang"] == "euc-jp"){
					Dll.getInstance().lang = "jp";
				} else if (PlatformFlashValue.value["lang"] == "pt-br"){
					Dll.getInstance().lang = "br";
				} else {
					Dll.getInstance().lang = PlatformFlashValue.value["lang"];
				}
				AppData.getInstance().setValue(PlatformFlashValue.value);
				Debug.isDebug = false;
			} else {
				Dll.getInstance().lang = "cn";
				Debug.isDebug = true;
			}
			if (!(PlatformFlashValue.value == null) && (PlatformFlashValue.value.hasOwnProperty("folder"))){
				this.$platformEntryUrl = PlatformFlashValue.value["folder"];
				_local1 = this.$platformEntryUrl.split("/");
				_local1.pop();
				_local1.pop();
				_local2 = (_local1.join("/") + "/");
				this.$platformIniUrl = (_local2 + "program/files/");
				this.$platformOutUrl = (((_local2 + "outresource/files_") + AppData.getInstance().platformOutResName) + "/");
			};
			if (((!((PlatformFlashValue.value == null))) && (PlatformFlashValue.value.hasOwnProperty("statisticsUrl")))){
				AppData.getInstance().statisticsUrl = PlatformFlashValue.value["statisticsUrl"];
			};
			StatisticsProxy.getInstance().setStartGameLoadingTime();
			Dll.getInstance().addEventListener(DllEvent.LOADING_COMPLETE, this.loadingComplete);
			Dll.getInstance().addEventListener(DllEvent.PROGRESS, this.loadingProgress);
			Dll.getInstance().addEventListener(DllEvent.COMPLETE, this.allComplete);
			Dll.getInstance().loadINIXML([(this.$platformEntryUrl + "ini.xml"), (((this.$platformEntryUrl + "outini_") + AppData.getInstance().platformOutResName) + ".xml")], this.$platformIniUrl, this.$platformOutUrl);
		}
		private function allComplete(_arg1:DllEvent):void{
			Dll.getInstance().removeEventListener(DllEvent.PROGRESS, this.mainProgress);
			var _local2:Loader = Dll.getInstance().getLoaderByName("main");
			this.mainLayer.addChild(Dll.getInstance().getLoaderByName("main"));
			this.removeLoadingLayer();
			AppLoading.getInstance().show();
		}
		private function removeLoadingLayer():void{
			this.removeLoadingLayerDelay();
		}
		private function removeLoadingLayerDelay():void{
			this.loadingSprite = null;
			removeChild(this.loadingLayer);
			this.loadingLayer = null;
		}
		private function loadingComplete(_arg1:DllEvent):void{
			Dll.getInstance().removeEventListener(DllEvent.PROGRESS, this.loadingProgress);
			Dll.getInstance().addEventListener(DllEvent.PROGRESS, this.mainProgress);
			this.loadingSprite = (Dll.getInstance().getDisplayObjectByName("Loading") as DisplayObject);
			var _local2:String = AppData.getInstance().platformOutResName;
			var _local3:Array = ["1", "2", "3", "4"];
			var _local4:int = int((Math.random() * _local3.length));
			var _local5 = (((("img" + _local3[_local4]) + "_") + _local2) + ".swf");
			var _local6:String = ((this.$platformEntryUrl + "loadingimg/") + _local5);
			(this.loadingSprite as Object).loadImg(_local6);
			if (this.loadingLayer){
				this.loadingLayer.addChild(this.loadingSprite);
			};
		}
		private function loadingProgress(_arg1:DllEvent):void{
		}
		private function mainProgress(_arg1:DllEvent):void{
			this.loadingSprite["progress"] = _arg1.data["progress"];
		}
		
		private function setStage():void{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			stage.tabChildren = false;
			stage.frameRate = 24;
			var cm:ContextMenu = new ContextMenu();
			cm.hideBuiltInItems();
			var cmi1:ContextMenuItem = new ContextMenuItem("v0.1", false, false);
			cm.customItems.push(cmi1);
			var cmi2:ContextMenuItem = new ContextMenuItem("2012_5", false, false);
			cm.customItems.push(cmi2);
			this.contextMenu = cm;
		}
	}
}